
public class BubbleSort {

	public BubbleSort(int[] arr) {
		boolean swapped = true;
		int j = 0, temp;
		System.out.println("Bubble sort\n");
		System.out.println("Befor sorting :");
		print(arr);
		while(swapped) {
			swapped = false;
			j++;
			
			for(int i=0;i<arr.length - j;i++) {
				if(arr[i] > arr[i+1]) {
					temp = arr[i];
					arr[i] = arr[i+1];
					arr[i+1] = temp;
					swapped = true;
				}
			}
		}
		System.out.println("\nAfter sorting :");
		print(arr);
	}
	
	public void print(int[] arrr) {
		for(int i = 0;i<arrr.length;i++) {
			System.out.print(arrr[i] +"  ");
		}
	}
	public static void main(String[] args) {
		new BubbleSort(new int[] {3,4,5,2,7,82,2,2,9});
	}

}
